package com.shaozi.nc.hibservice;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.shaozi.data.hib.dao.BaseHibDao;
import com.shaozi.data.hib.service.BaseServiceImpl;
import com.shaozi.lib.throwable.SzException;
import com.shaozi.utils.common.SysUtils;
import com.shaozi.nc.data.hibVO.CrmPipelineStageVO;

@Service(value = "crmPipelineStageService")
public class CrmPipelineStageService extends BaseServiceImpl<CrmPipelineStageVO> {

	private Logger logger = Logger.getLogger(CrmPipelineStageService.class);

	@Autowired
	public CrmPipelineStageService(BaseHibDao<CrmPipelineStageVO> baseHibDao) {
		super(baseHibDao);
	}

	/**
	 * 
	 * @param pipelineIds
	 * @return
	 * can be empty
	 * @throws SzException
	 */
	public List<Integer> getStageIds(List<Integer> pipelineIds) throws SzException {

		String hql = "from CrmPipelineStageVO where order='-2' and isDelete=0 and pipelineId in ("
				+ SysUtils.combineList(pipelineIds, ",") + ")";

		List<CrmPipelineStageVO> stageVos = getDao().getDaoSupport().queryObjects(hql, -1, -1);
		try {
			List ids = SysUtils.getArrayFieldVals(stageVos, "id");
			
			return ids;
		} catch (IllegalArgumentException | IllegalAccessException e) {
			logger.error(SzException.getStackMessage(e));
		}
		return null;

	}
}
